<?php
defined('BASEPATH') OR exit('No direct script access allowed');


use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

class Message extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		
	}
    
	public function publish()
	{
		$message=$this->input->get('message');
		//新建MQ连接
		$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
		
		//新建一个频道
		$channel = $connection->channel();
		
		//声明一个队列
		$channel->queue_declare('hello', false, false, false, false);

		//创建一个消息
		$msg = new AMQPMessage($message);
		//发布消息
		$channel->basic_publish($msg, '', 'hello');
		

		echo " [x] Sent 'Hello World!'\n";
		
		//关闭频道
		$channel->close();
		//关闭MQ连接
		$connection->close();
		
		echo " [x] close 'RabbmitMQ!'\n";
	}
	
	
	
	
	
}
